/**
 * 
 */
package com.EstateManager.Utils;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;




import org.apache.commons.beanutils.BeanMap;
import org.omg.CORBA.PUBLIC_MEMBER;

/**
 * 创建时间 : 上午10:11:23
 * @author Yonggang Liu
 *
 * CommenUtils.java
 */
public class CommenUtils {
	
	/**
	 * 获取指定地址下的数据
	 * @param urlPath
	 * */
		public static String getJsonString(String urlPath) throws Exception {  
	        URL url = new URL(urlPath);  
	        HttpURLConnection connection = (HttpURLConnection) url.openConnection();  
	        connection.connect();  
	        InputStream inputStream = connection.getInputStream();  
	        //对应的字符编码转换  
	        Reader reader = new InputStreamReader(inputStream, "UTF-8");  
	        BufferedReader bufferedReader = new BufferedReader(reader);  
	        String str = null;  
	        StringBuffer sb = new StringBuffer();  
	        while ((str = bufferedReader.readLine()) != null) {  
	            sb.append(str);  
	        }  
	        reader.close();  
	        connection.disconnect();  
	        return sb.toString();  
    }
		/***/
		 public static Object mapToObject(Map<String, Object> map, Class<?> beanClass) throws Exception {    
		        if (map == null)  
		            return null;  
		   
		        Object obj = beanClass.newInstance();  
		      
		        org.apache.commons.beanutils.BeanUtils.populate(obj, map);  
		   
		        return obj;  
		    }    
		       
		    public static Map<?, ?> objectToMap(Object obj) {  
		        if(obj == null)  
		            return null;   
		        return new BeanMap(obj);
		       
		    }    
}
